import request from '@/plugins/request'
import { IResponseData } from '@/types/request-base'
import { json2FormData } from '@/utils'
// 查询相关接口

/**
 * 查询所有办事处
 */
export function getAllOffice() {
  return request<IResponseData>({
    method: 'get',
    url: `/app/v1/user/organization/agencies`
  })
}

/**
 * 分页查询组织
 * @param {object} data 参数
 */
export function getOrganizationPage({ page, rows, sort, order, filtersRaw, sortersRaw, paramsRaw, pageFlag }: any) {
  const params = {
    page,
    rows,
    sort: sort || '',
    order: order || 'DESC',
    pageFlag: pageFlag !== false ? true : false,
    onlyCountFlag: false,
    filtersRaw: JSON.stringify(filtersRaw),
    sortersRaw: JSON.stringify(sortersRaw),
    paramsRaw: JSON.stringify(paramsRaw)
  }
  const data = json2FormData(params)
  return request<IResponseData>({
    method: 'post',
    url: `/app/v1/user/organization/page`,
    data
  })
}

/**
 * 查询客户经理
 * @param {object} data 参数
 */
export function getCustomerManagerPage({ page, rows, sort, order, filtersRaw, sortersRaw, paramsRaw, pageFlag }: any) {
  const defautlSorter: object[] = [] // [{ id: 'createTime', property: 'createTime', direction: 'DESC' }]
  const params = {
    page,
    rows,
    sort: sort || '',
    order: order || 'DESC',
    pageFlag: pageFlag !== false ? true : false,
    onlyCountFlag: false,
    filtersRaw: JSON.stringify(filtersRaw),
    sortersRaw: JSON.stringify(sortersRaw && sortersRaw.length > 0 ? sortersRaw : defautlSorter),
    paramsRaw: JSON.stringify(paramsRaw)
  }
  const data = json2FormData(params)
  return request<IResponseData>({
    method: 'post',
    url: `/app/v1/user/queryAccountOrgPersonByParams`,
    data
  })
}

/**
 * 查询客户经理
 * @param {object} data 参数
 */
export function getPersonOrgPage({ page, rows, sort, order, filtersRaw, sortersRaw, paramsRaw, pageFlag }: any) {
  const defautlSorter: object[] = []
  const params = {
    page,
    rows,
    sort: sort || '',
    order: order || 'DESC',
    pageFlag: pageFlag !== false ? true : false,
    onlyCountFlag: false,
    filtersRaw: JSON.stringify(filtersRaw),
    sortersRaw: JSON.stringify(sortersRaw && sortersRaw.length > 0 ? sortersRaw : defautlSorter),
    paramsRaw: JSON.stringify(paramsRaw)
  }
  const data = json2FormData(params)
  return request<IResponseData>({
    method: 'post',
    url: `/app/v1/user/personOrg/page`,
    data
  })
}
/**
 * 查询门店
 * @param {object} data 参数
 */
export function getMdmServiceShop({ page, rows, sort, order, filtersRaw, sortersRaw, paramsRaw, pageFlag }: any) {
  const defautlSorter: object[] = [] // [{ id: 'createTime', property: 'createTime', direction: 'DESC' }]
  const params = {
    page,
    rows,
    sort: sort || '',
    order: order || 'DESC',
    pageFlag: pageFlag !== false ? true : false,
    onlyCountFlag: false,
    filtersRaw: JSON.stringify(filtersRaw),
    sortersRaw: JSON.stringify(sortersRaw && sortersRaw.length > 0 ? sortersRaw : defautlSorter),
    paramsRaw: JSON.stringify(paramsRaw)
  }
  const data = json2FormData(params)
  return request<IResponseData>({
    method: 'post',
    url: `/app/v1/mdmService/getShopPage`,
    data
  })
}

/**
 * 查询业务账号
 * @param {object} data 参数
 */
export function getMdmServiceAccount({ page, rows, sort, order, filtersRaw, sortersRaw, paramsRaw, pageFlag }: any) {
  const defautlSorter: object[] = [] // [{ id: 'createTime', property: 'createTime', direction: 'DESC' }]
  const params = {
    page,
    rows,
    sort: sort || '',
    order: order || 'DESC',
    pageFlag: pageFlag !== false ? true : false,
    onlyCountFlag: false,
    filtersRaw: JSON.stringify(filtersRaw),
    sortersRaw: JSON.stringify(sortersRaw && sortersRaw.length > 0 ? sortersRaw : defautlSorter),
    paramsRaw: JSON.stringify(paramsRaw)
  }
  const data = json2FormData(params)
  return request<IResponseData>({
    method: 'post',
    url: `/app/v1/mdmService/getAccountPage`,
    data
  })
}

/**
 * 查询国别
 * @param {object} data 参数
 */
export function getMdmCountry({ page, rows, sort, order, filtersRaw, sortersRaw, paramsRaw, pageFlag }: any) {
  const defautlSorter: object[] = [] // [{ id: 'createTime', property: 'createTime', direction: 'DESC' }]
  const params = {
    page,
    rows,
    sort: sort || '',
    order: order || 'DESC',
    pageFlag: pageFlag !== false ? true : false,
    onlyCountFlag: false,
    filtersRaw: JSON.stringify(filtersRaw),
    sortersRaw: JSON.stringify(sortersRaw && sortersRaw.length > 0 ? sortersRaw : defautlSorter),
    paramsRaw: JSON.stringify(paramsRaw)
  }
  const data = json2FormData(params)
  return request<IResponseData>({
    method: 'post',
    url: `/app/v1/mdmService/country/page`,
    data
  })
}

/**
 * 查询原商家客户信息
 * @param {object} data 参数
 */
export function getMdmServiceCustomer({ page, rows, sort, order, filtersRaw, sortersRaw, paramsRaw, pageFlag }: any) {
  const defautlSorter: object[] = [] // [{ id: 'createTime', property: 'createTime', direction: 'DESC' }]
  const params = {
    page,
    rows,
    sort: sort || '',
    order: order || 'DESC',
    pageFlag: pageFlag !== false ? true : false,
    onlyCountFlag: false,
    filtersRaw: JSON.stringify(filtersRaw),
    sortersRaw: JSON.stringify(sortersRaw && sortersRaw.length > 0 ? sortersRaw : defautlSorter),
    paramsRaw: JSON.stringify(paramsRaw)
  }
  const data = json2FormData(params)
  return request<IResponseData>({
    method: 'post',
    // url: `/app/v1/ctmMdmCustomer/listByAgencyCode`, // 所有商家信息
    url: `/app/v1/ctmMdmCustomer/pageOfCooperationEnd`,
    data
  })
}
